﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.DL.Data.Common;
using ScrumTable.DL.Data.Generic.Cache;
using ScrumTable.DL.Data.Generic.Properties;
using ScrumTable.DL.Data.Schema;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.DL.Data.Generic
{
    /// <summary>
    /// This class specifies the iteration data wrapper for a team foundation
    /// server (UserStory) work item.
    /// </summary>
    /// <remarks>The implementation of the data object class follows the Anything pattern.</remarks>
    internal class UserStoryDataObject : WorkItemDataObjectBase<UserStorySchema>
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the underlying system order index. This property can be used
        /// to output the elements in the order given by the data connector.
        /// </summary>
        public override double OrderIndex 
        {
            get
            {
                return (this[ScrumTableSchema.UserStorySchema.Ranking] != null) 
                    ? (double)this[ScrumTableSchema.UserStorySchema.Ranking]
                    : 0;
            } 
        }

        /// <summary>
        /// Gets the corresponding typed data schema (e.g. UserStorySchema / TaskSchema / ...).
        /// </summary>
        protected override sealed UserStorySchema TypedSchema { get { return ScrumTableSchema.UserStorySchema; } }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new UserStoryDataObject instance, no public constructor
        /// needed.
        /// </summary>
        internal UserStoryDataObject(DataAccessObjectBase parent, CacheWorkItem userStory)
            : base(parent, userStory)
        {
            NameSchemaMappings.Add(TypedSchema.Description, GetDescription, SetDescription);
            NameSchemaMappings.Add(TypedSchema.MemberId, GetMemberId, SetMemberId);
            NameSchemaMappings.Add(TypedSchema.Name, GetName, SetName);
            NameSchemaMappings.Add(TypedSchema.Ranking, GetRanking, SetRanking);
            NameSchemaMappings.Add(TypedSchema.State, GetState, SetState);
            NameSchemaMappings.Add(TypedSchema.StoryPoints, GetStoryPoints, SetStoryPoints);
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        private object GetDescription(SchemaBase schema) { return WorkItem.Description; }
        private void SetDescription(SchemaBase schema, object value) { WorkItem.Description = (string)value; }

        private object GetMemberId(SchemaBase schema) { return WorkItem.AssignedToMemberChain; }
        private void SetMemberId(SchemaBase schema, object value) { WorkItem.AssignedToMemberChain = (ValueChain<string>)value; }

        private object GetName(SchemaBase schema) { return WorkItem.Name; }
        private void SetName(SchemaBase schema, object value) { WorkItem.Name = (string)value; }

        private object GetRanking(SchemaBase schema) { return WorkItem[ScrumTableSchema.UserStorySchema.Ranking.SchemaMappedName]; }
        private void SetRanking(SchemaBase schema, object value) { WorkItem[ScrumTableSchema.UserStorySchema.Ranking.SchemaMappedName] = value; }

        private object GetState(SchemaBase schema) { return WorkItem.State; }
        private void SetState(SchemaBase schema, object value) { WorkItem.State = (string)value; }

        private object GetStoryPoints(SchemaBase schema) { return WorkItem[ScrumTableSchema.UserStorySchema.StoryPoints.SchemaMappedName]; }
        private void SetStoryPoints(SchemaBase schema, object value) { WorkItem[ScrumTableSchema.UserStorySchema.StoryPoints.SchemaMappedName] = value; }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}